package com.niuke;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

/**
 * 10. 不开心的小朋友
 * https://blog.csdn.net/banxia_frontend/article/details/131447250
 */
public class NiukeMoni12 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine()); // 摇摇车数量
        String str = scanner.nextLine();
        String[] xiaoPengYou = str.split(" ");

        // -----------------------------------------------------------
        Set<Integer> wanShua = new HashSet<>();
        LinkedList<Integer> paiDui = new LinkedList<>();

        int res = 0;
        for (int i = 0; i < xiaoPengYou.length; i++) {
            Integer curr = Integer.parseInt(xiaoPengYou[i]);
            if (wanShua.contains(curr)) {
                System.out.println("玩耍后离开 " + curr);
                wanShua.remove(curr); // 已经在玩摇摇车的选择离开

                if (paiDui.size() > 0) { // 如果有排队的，把排队的先上去玩
                    System.out.println("排队添加 " + paiDui.get(0));
                    wanShua.add(paiDui.removeFirst());
                }

            } else {
                if (wanShua.size() == n) { // 没有位置需要排队，如果排队里已经有的是不开心离开的
                    if (paiDui.contains(curr)) {
                        System.out.println("不开心离开 " + curr);
                        paiDui.remove(curr);
                        res++;
                    } else {
                        System.out.println("排队 " + curr);
                        paiDui.add(curr);
                    }
                } else { // 有位置直接上去玩耍
                    System.out.println("直接添加 " + curr);
                    wanShua.add(curr);
                }
            }
        }


        System.out.println(res);
    }

}
